//创建栈数据结构
class Stack {
    constructor() {
        this.items = [];
    }

    push(element) {
        this.items.push(element);
    }

    pop() {
        return this.items.pop();
    }

    peek() {
        return this.items[this.items.length - 1];
    }

    isEmpty() {
        return this.items.length === 0;
    }

    size() {
        return this.items.length;
    }

    print() {
        console.log(this.items.toString());
    }
}

// 使用
const stack = new Stack();

stack.push(1);
stack.push(2);
stack.push(3);

stack.print(); // 3,2,1

stack.pop();
console.log(stack.peek()); // 2



